package com.liip.platform.config.web;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpHeaders;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

 
/**
 * 	拦截器注册
 * @author Administrator
 *
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {
//    @Resource
//    private TokenInterceptor tokenInterceptor ;
//    public void addInterceptors(InterceptorRegistry registry) {
//        registry.addInterceptor(tokenInterceptor)
//        .addPathPatterns("/api/**")
//		.excludePathPatterns("/swagger-resources/**","/webjars/**","/swagger-ui.html/**","/v2/**","/csrf/**","/error/**");
//    }
    
    /**
     * 跨域配置
     */
    @Bean
    public WebMvcConfigurer corsConfigurer() {
		return new WebMvcConfigurer() {
			@Override
			public void addCorsMappings(CorsRegistry registry) {
				registry.addMapping("/**")
						.allowedOrigins("*")//允许跨域的域名，*表示所有
						.allowedMethods("*")//允许任何方法(get/post等)
						.allowedHeaders("*")//
						.allowCredentials(true)//允许任何请求头
						.exposedHeaders(HttpHeaders.SET_COOKIE)//带上cookie信息
						.maxAge(3600L);//表明3600秒内，不需要在发送预检请求
			}
		};
    }
}
